package cfca.paperless.client.servlet._3_assist._3_15_GetKeywordLocationsInPdf;

import java.io.File;
import org.apache.commons.io.FileUtils;

import cfca.paperless.client.servlet.PaperlessClient;
import cfca.paperless.client.servlet.PaperlessConfig;
import cfca.paperless.client.util.IoUtil;
import cfca.paperless.client.util.StringUtil;

public class GetKeywordLocationsInPdfTest01 {

    public static void main(String[] args) throws Exception {
        try {
            PaperlessClient clientBean = new PaperlessClient(PaperlessConfig.assistUrl, 10000, 60000);// 无纸化辅助接口的访问URL

            String filePath = "./TestData/bigFile.pdf";
            byte[] pdf = FileUtils.readFileToByteArray(new File(filePath));

            // 操作员编码或者机构号
            String operatorCode = PaperlessConfig.operatorCode;

            // 取得转换后的PDF文件数据
            String result = clientBean.getKeywordLocationsInPdf(pdf, "任何人或组织", operatorCode);

            String code = StringUtil.getNodeText(result, "Code");
            if (!code.equals("200")) {
                System.out.println("getKeywordLocationsInPdf");
                System.out.println(result);
            } else {
                Object [] locationArr = StringUtil.getXmlFieldArr(result, "Location");
                for(Object obj : locationArr) {
                    System.out.println("Location:" + obj.toString());
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
